/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.maleskoding.jmplurk.ui.components;

import com.sun.lwuit.ComboBox;
import com.sun.lwuit.Component;
import com.sun.lwuit.Label;
import com.sun.lwuit.List;
import com.sun.lwuit.list.ListCellRenderer;
import com.sun.lwuit.plaf.Border;
import java.util.Hashtable;

/**
 *
 * @author Petra Barus
 */
public class QualifierCombo extends ComboBox implements ListCellRenderer {

    Hashtable fgcolor, bgcolor;
    Label focus;

    public QualifierCombo() {
        super(new String[]{"loves", "likes", "shares",
                    "gives", "hates", "wants", "wishes", "needs", "will", "hopes",
                    "asks", "has", "was", "wonders", "feels", "thinks",
                    "says", "is", ":", "freestyle"});
        initMaps();
        init();
    }

    private void init() {
        focus = new Label();
        focus.getStyle().setBgColor(0x000000);
        focus.getStyle().setMargin(0, 0, 0, 0);
    }

    private void initMaps() {
        fgcolor = new Hashtable();
        bgcolor = new Hashtable();
        fgcolor.put("loves", new Integer(0xffffff));
        bgcolor.put("loves", new Integer(0xb20c0c));
        fgcolor.put("likes", new Integer(0xffffff));
        bgcolor.put("likes", new Integer(0xcb2728));
        fgcolor.put("shares", new Integer(0xffffff));
        bgcolor.put("shares", new Integer(0xa74949));
        fgcolor.put("gives", new Integer(0xffffff));
        bgcolor.put("gives", new Integer(0x620e0e));
        fgcolor.put("hates", new Integer(0xffffff));
        bgcolor.put("hates", new Integer(0x111111));
        fgcolor.put("wants", new Integer(0xffffff));
        bgcolor.put("wants", new Integer(0x8db241));
        fgcolor.put("wishes", new Integer(0xffffff));
        bgcolor.put("wishes", new Integer(0x5bb017));
        fgcolor.put("needs", new Integer(0xffffff));
        bgcolor.put("needs", new Integer(0x7a9a37));
        fgcolor.put("will", new Integer(0xffffff));
        bgcolor.put("will", new Integer(0xb46db9));
        fgcolor.put("hopes", new Integer(0xffffff));
        bgcolor.put("hopes", new Integer(0xe05be9));
        fgcolor.put("asks", new Integer(0xffffff));
        bgcolor.put("asks", new Integer(0x8361bc));
        fgcolor.put("has", new Integer(0xffffff));
        bgcolor.put("has", new Integer(0x777777));
        fgcolor.put("was", new Integer(0xffffff));
        bgcolor.put("was", new Integer(0x525252));
        fgcolor.put("wonders", new Integer(0xffffff));
        bgcolor.put("wonders", new Integer(0x2e4e9e));
        fgcolor.put("feels", new Integer(0xffffff));
        bgcolor.put("feels", new Integer(0x2d83be));
        fgcolor.put("thinks", new Integer(0xffffff));
        bgcolor.put("thinks", new Integer(0x689cc1));
        fgcolor.put("says", new Integer(0xffffff));
        bgcolor.put("says", new Integer(0xe2560b));
        fgcolor.put("is", new Integer(0xffffff));
        bgcolor.put("is", new Integer(0xe57c43));
        fgcolor.put(":", new Integer(0x000000));
        bgcolor.put(":", new Integer(0xffffff));
        fgcolor.put("freestyle", new Integer(0x000000));
        bgcolor.put("freestyle", new Integer(0xffffff));
        getStyle().setBgTransparency(0);
    }

    private int getFgColor(String qualifier) {
        return ((Integer) fgcolor.get(qualifier)).intValue();
    }

    private int getBgColor(String qualifier) {
        return ((Integer) bgcolor.get(qualifier)).intValue();
    }

    protected List createPopupList() {
        List l = super.createPopupList();
        l.setListCellRenderer(this);
        return l;
    }

    public Component getListCellRendererComponent(List list, Object o, int i, boolean bln) {
        String s = o.toString();
        Label l = new Label(s);
        l.getStyle().setFgColor(getFgColor(s));
        l.getStyle().setBgColor(getBgColor(s));
        l.getStyle().setMargin(0, 0, 10, 2);
        return l;
    }

    public Component getListFocusComponent(List list) {
        return focus;
    }
}
